* make shape a subclass of Format.
* correct type of 2nd param passed to SHPCreateSimpleObject
mynav.h
navilink.h
session.h
+ shape.h
shapelib/shapefil.h
strptime.h
units.h
mynav.h \
navilink.h \
session.h \
+ shape.h \
shapelib/shapefil.h \
strptime.h \
units.h \
position.h radius.h reverse_route.h smplrout.h sort.h stackfilter.h \
swapdata.h trackfilter.h transform.h validate.h gbversion.h vecs.h \
format.h ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
- src/core/xmltag.h legacyformat.h mynav.h xcsv.h garmin_fs.h \
- jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h \
- jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \
- jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \
- jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
+ src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+ legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
+ jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
+ jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
+ jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
+ src/core/textstream.h
formspec.o: formspec.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
src/core/optional.h
jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
jeeps/gpsrqst.h garmin_tables.h grtcirc.h jeeps/gpsserial.h vecs.h \
ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
- src/core/xmltag.h legacyformat.h mynav.h xcsv.h src/core/textstream.h
+ src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+ legacyformat.h mynav.h xcsv.h src/core/textstream.h
garmin_device_xml.o: garmin_device_xml.cc defs.h config.h zlib/zlib.h \
zlib/zconf.h formspec.h inifile.h gbfile.h session.h \
src/core/datetime.h src/core/optional.h garmin_device_xml.h \
src/core/datetime.h src/core/optional.h
interpolate.o: interpolate.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
- src/core/optional.h interpolate.h filter.h grtcirc.h
+ src/core/optional.h interpolate.h filter.h grtcirc.h \
+ src/core/logging.h
itracku.o: itracku.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
gbser.h
formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
src/core/optional.h explorist_ini.h format.h gbser.h magellan.h vecs.h \
ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
- src/core/xmltag.h legacyformat.h mynav.h xcsv.h garmin_fs.h \
- jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h \
- jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \
- jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \
- jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
+ src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+ legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
+ jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
+ jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
+ jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
+ src/core/textstream.h
main.o: main.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
cet_util.h csv_util.h filter.h filter_vecs.h arcdist.h bend.h \
polygon.h position.h radius.h reverse_route.h smplrout.h sort.h \
stackfilter.h swapdata.h trackfilter.h transform.h validate.h format.h \
src/core/file.h src/core/usasciicodec.h vecs.h ggv_bin.h gpx.h \
- src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
- xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
+ src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
+ shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
+ garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h
shape.o: shape.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
- shapelib/shapefil.h
+ shape.h format.h shapelib/shapefil.h
shapelib/dbfopen.o: shapelib/dbfopen.c shapelib/shapefil.h
shapelib/safileio.o: shapelib/safileio.c shapelib/shapefil.h
shapelib/shpopen.o: shapelib/shpopen.c shapelib/shapefil.h
vecs.o: vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
vecs.h format.h ggv_bin.h gpx.h src/core/file.h \
- src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
- xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
+ src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
+ shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
+ garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \
inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
garmin_tables.h jeeps/gpsmath.h jeeps/gpsport.h src/core/file.h \
src/core/xmlstreamwriter.h xmlgeneric.h
-yahoo.o: yahoo.cc defs.h config.h zlib/zlib.h zlib/zconf.h config.h \
- formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
- src/core/optional.h yahoo.h format.h xmlgeneric.h
+yahoo.o: yahoo.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
+ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
+ yahoo.h format.h xmlgeneric.h
zlib/adler32.o: zlib/adler32.c zlib/zutil.h zlib/zlib.h zlib/zconf.h \
config.h
zlib/compress.o: zlib/compress.c zlib/zlib.h zlib/zconf.h config.h
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <QtCore/QLatin1String>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVector>
+
+#include <assert.h> // for assert
+
+#include <QtCore/QByteArray> // for QByteArray
+#include <QtCore/QLatin1String> // for QLatin1String
+#include <QtCore/QString> // for QString, QString::SkipEmptyParts
+#include <QtCore/QStringList> // for QStringList
+#include <QtCore/QVector> // for QVector
+#include <QtCore/Qt> // for CaseInsensitive
+#include <QtCore/QtGlobal> // for qPrintable
#include "defs.h"
+#include "shape.h"
#include "shapelib/shapefil.h"
-#include <cstdlib>
+
#if SHAPELIB_ENABLED
-static SHPHandle ihandle;
-static DBFHandle ihandledb;
-static SHPHandle ohandle;
-static DBFHandle ohandledb;
#define MYNAME "shape"
-static unsigned poly_count;
-static double* polybufx;
-static double* polybufy;
-static double* polybufz;
-static QString ifname;
-static QString ofname;
-static int nameFieldIdx; // the field index of the field with fieldName "name" in the output DBF.
-
-static char* opt_name = nullptr;
-static char* opt_url = nullptr;
-
-static
-QVector<arglist_t> shp_args = {
- {
- "name", &opt_name, "Source for name field in .dbf",
- nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
- },
- {
- "url", &opt_url, "Source for URL field in .dbf",
- nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
- },
-};
-
-
/************************************************************************/
/* SHPOpenGpsbabel() */
/************************************************************************/
-static SHPHandle SHPAPI_CALL
-SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
+SHPHandle SHPAPI_CALL
+ShapeFormat::SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
{
SAHooks sHooks;
/* shape file with read/write access. */
/************************************************************************/
-static SHPHandle SHPAPI_CALL
-SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
+SHPHandle SHPAPI_CALL
+ShapeFormat::SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
{
SAHooks sHooks;
/* Open a .dbf file. */
/************************************************************************/
-static DBFHandle SHPAPI_CALL
-DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
{
SAHooks sHooks;
/* Create a new .dbf file. */
/************************************************************************/
-static DBFHandle SHPAPI_CALL
-DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
{
SAHooks sHooks;
#ifdef SHPAPI_UTF8_HOOKS
SASetupUtf8Hooks(&sHooks);
- return DBFCreateLL(pszFilename.toUtf8().constData(), pszCodePage , &sHooks);
+ return DBFCreateLL(pszFilename.toUtf8().constData(), pszCodePage, &sHooks);
#else
SASetupDefaultHooks(&sHooks);
- return DBFCreateLL(qPrintable(pszFilename), pszCodePage , &sHooks);
+ return DBFCreateLL(qPrintable(pszFilename), pszCodePage, &sHooks);
#endif
}
/* Create a new .dbf file with default code page LDID/87 (0x57) */
/************************************************************************/
-static DBFHandle SHPAPI_CALL
-DBFCreateGpsbabel(const QString& pszFilename)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFCreateGpsbabel(const QString& pszFilename)
{
return DBFCreateExGpsbabel(pszFilename, "LDID/87"); // 0x57
}
#endif
-static
-void dump_fields()
+void ShapeFormat::dump_fields() const
{
char name[12];
warning(MYNAME ": Database fields:\n");
fatal("\n");
}
-static
-void check_field_index(const int fieldIdx)
+void ShapeFormat::check_field_index(const int fieldIdx) const
{
const int maxFields = DBFGetFieldCount(ihandledb);
if (fieldIdx < 0 || fieldIdx >= maxFields) {
}
}
-static
-int get_field_index(const QString& fieldName)
+int ShapeFormat::get_field_index(const QString& fieldName) const
{
const int fieldIdx = DBFGetFieldIndex(ihandledb, CSTR(fieldName));
if (fieldIdx < 0) {
return fieldIdx;
}
-static void
-my_rd_init(const QString& fname)
+void
+ShapeFormat::rd_init(const QString& fname)
{
ifname = fname;
// TODO: The .prj file can define the the coordinate system and projection information.
}
}
-static void
-my_read()
+void
+ShapeFormat::read()
{
- // option processing here instead of in my_rd_init
+ // option processing here instead of in rd_init
// lets the results of option processing be automatic.
int nameidx;
int urlidx;
}
-static void
-my_rd_deinit()
+void
+ShapeFormat::rd_deinit()
{
SHPClose(ihandle);
DBFClose(ihandledb);
ifname.clear();
}
-static void
-my_wr_init(const QString& fname)
+void
+ShapeFormat::wr_init(const QString& fname)
{
ofname = fname;
}
-static void
-my_wr_deinit()
+void
+ShapeFormat::wr_deinit()
{
SHPClose(ohandle);
DBFClose(ohandledb);
ofname.clear();
}
-static void
-my_write_wpt(const Waypoint* wpt)
+void
+ShapeFormat::write_wpt(const Waypoint* wpt) const
{
// note that the z coordinate (&wpt->altitude) does not apply
// to SHPT_POINT.
// We could potentially write SHPT_POINTZ, but we would have
// to address what to do when we don't have altitude data.
SHPObject* shpobject = SHPCreateSimpleObject(SHPT_POINT, 1,
- &wpt->longitude,
- &wpt->latitude,
- &wpt->altitude);
+ &wpt->longitude,
+ &wpt->latitude,
+ &wpt->altitude);
int iShape = SHPWriteObject(ohandle, -1, shpobject);
SHPDestroyObject(shpobject);
DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
CSTR(wpt->shortname));
}
-static void
-poly_init(const route_head* rte)
+void
+ShapeFormat::poly_init(const route_head* rte)
{
const int ct = rte->rte_waypt_ct;
poly_count = 0;
- polybufx = (double*) xcalloc(ct, sizeof(double));
- polybufy = (double*) xcalloc(ct, sizeof(double));
- polybufz = (double*) xcalloc(ct, sizeof(double));
+ polybufx = new double[ct];
+ polybufy = new double[ct];
+ polybufz = new double[ct];
}
-static void
-poly_point(const Waypoint* wpt)
+void
+ShapeFormat::poly_point(const Waypoint* wpt)
{
polybufx[poly_count] = wpt->longitude;
polybufy[poly_count] = wpt->latitude;
poly_count++;
}
-static void
-poly_deinit(const route_head* rte)
+void
+ShapeFormat::poly_deinit(const route_head* rte)
{
// note that the z coordinate (polybufz) does not apply
// to SHPT_ARC.
// We could potentially write SHPT_ARCZ, but we would have
// to address what to do when we don't have altitude data.
+ assert(rte->rte_waypt_ct == poly_count);
SHPObject* shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count,
- polybufx, polybufy, polybufz);
+ polybufx, polybufy, polybufz);
int iShape = SHPWriteObject(ohandle, -1, shpobject);
SHPDestroyObject(shpobject);
DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
CSTR(rte->rte_name));
- xfree(polybufx);
- xfree(polybufy);
- xfree(polybufz);
+ delete[] polybufx;
+ delete[] polybufy;
+ delete[] polybufz;
poly_count = 0;
}
-static void
-my_write()
+void
+ShapeFormat::write()
{
// shape files can only contain one shape type in addition
// to the null shape type.
// route/track data.
switch (global_opts.objective) {
case wptdata:
- case unknown_gpsdata:
+ case unknown_gpsdata: {
ohandle = SHPCreateGpsbabel(ofname, SHPT_POINT);
if (ohandle == nullptr) {
qPrintable(ofname));
}
nameFieldIdx=DBFAddField(ohandledb,"name",FTString,100,0);
- waypt_disp_all(my_write_wpt);
+ auto write_wpt_lambda = [this](const Waypoint* wpt)->void {
+ write_wpt(wpt);
+ };
+ waypt_disp_all(write_wpt_lambda);
break;
+ }
case rtedata:
- case trkdata:
+ case trkdata: {
ohandle = SHPCreateGpsbabel(ofname, SHPT_ARC);
if (ohandle == nullptr) {
qPrintable(ofname));
}
nameFieldIdx=DBFAddField(ohandledb,"name",FTString,100,0);
+ auto poly_init_lambda = [this](const route_head* rte)->void {
+ poly_init(rte);
+ };
+ auto poly_deinit_lambda = [this](const route_head* rte)->void {
+ poly_deinit(rte);
+ };
+ auto poly_point_lambda = [this](const Waypoint* wpt)->void {
+ poly_point(wpt);
+ };
if (global_opts.objective == trkdata) {
- track_disp_all(poly_init, poly_deinit, poly_point);
+ track_disp_all(poly_init_lambda, poly_deinit_lambda, poly_point_lambda);
} else { // rtedata
- route_disp_all(poly_init, poly_deinit, poly_point);
+ route_disp_all(poly_init_lambda, poly_deinit_lambda, poly_point_lambda);
}
break;
+ }
case posndata:
fatal(MYNAME ": Realtime positioning not supported\n");
break;
}
}
-
-ff_vecs_t shape_vecs = {
- ff_type_file,
- FF_CAP_RW_ALL,
- my_rd_init,
- my_wr_init,
- my_rd_deinit,
- my_wr_deinit,
- my_read,
- my_write,
- nullptr,
- &shp_args,
- CET_CHARSET_ASCII, 0 /* CET-REVIEW */
- , NULL_POS_OPS,
- nullptr
-};
#endif /* SHAPELIB_ENABLED */
--- /dev/null
+/*
+
+ ESRI shp/shx shapefiles.
+
+ Copyright (C) 2003 Robert Lipe, robertlipe+source@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ */
+#ifndef SHAPE_H_INCLUDED_
+#define SHAPE_H_INCLUDED_
+
+#include <QtCore/QString> // for QString
+#include <QtCore/QVector> // for QVector
+
+#include "defs.h" // for arglist_t, ARGTYPE_STRING, Waypoint, route_head, CET_CHARSET_ASCII, FF_CAP_RW_ALL, ff_cap, ff_type, ff_type_file
+#include "format.h" // for Format
+#include "shapelib/shapefil.h" // for DBFHandle, SHPAPI_CALL, SHPHandle
+
+
+#if SHAPELIB_ENABLED
+class ShapeFormat : public Format
+{
+public:
+ QVector<arglist_t>* get_args() override
+ {
+ return &shp_args;
+ }
+
+ ff_type get_type() const override
+ {
+ return ff_type_file;
+ }
+
+ QVector<ff_cap> get_cap() const override
+ {
+ return FF_CAP_RW_ALL;
+ }
+
+ QString get_encode() const override
+ {
+ return CET_CHARSET_ASCII;
+ }
+
+ int get_fixed_encode() const override
+ {
+ return 0;
+ }
+
+ void rd_init(const QString& fname) override;
+ void read() override;
+ void rd_deinit() override;
+ void wr_init(const QString& fname) override;
+ void write() override;
+ void wr_deinit() override;
+
+private:
+ static SHPHandle SHPAPI_CALL SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess);
+ static SHPHandle SHPAPI_CALL SHPCreateGpsbabel(const QString& pszLayer, int nShapeType);
+ static DBFHandle SHPAPI_CALL DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess);
+ static DBFHandle SHPAPI_CALL DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage);
+ void dump_fields() const;
+ void check_field_index(int fieldIdx) const;
+ int get_field_index(const QString& fieldName) const;
+ void write_wpt(const Waypoint* wpt) const;
+ void poly_init(const route_head* rte);
+ void poly_point(const Waypoint* wpt);
+ void poly_deinit(const route_head* rte);
+
+ SHPHandle ihandle;
+ DBFHandle ihandledb;
+ SHPHandle ohandle;
+ DBFHandle ohandledb;
+
+ int poly_count;
+ double* polybufx;
+ double* polybufy;
+ double* polybufz;
+ QString ifname;
+ QString ofname;
+ int nameFieldIdx; // the field index of the field with fieldName "name" in the output DBF.
+
+ char* opt_name = nullptr;
+ char* opt_url = nullptr;
+
+ QVector<arglist_t> shp_args = {
+ {
+ "name", &opt_name, "Source for name field in .dbf",
+ nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
+ },
+ {
+ "url", &opt_url, "Source for URL field in .dbf",
+ nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
+ },
+ };
+#endif /* SHAPELIB_ENABLED */
+};
+#endif // SHAPE_H_INCLUDED_
#include "format.h"
#include "ggv_bin.h"
#include "gpx.h"
-#include "yahoo.h"
#include "legacyformat.h"
#include "mynav.h"
+#include "shape.h"
#include "xcsv.h"
+#include "yahoo.h"
extern ff_vecs_t geo_vecs;
extern ff_vecs_t saroute_vecs;
extern ff_vecs_t navicache_vecs;
extern ff_vecs_t psit_vecs;
-#if SHAPELIB_ENABLED
-extern ff_vecs_t shape_vecs;
-#endif
extern ff_vecs_t gpl_vecs;
extern ff_vecs_t text_vecs;
extern ff_vecs_t html_vecs;
LegacyFormat navicache_fmt {navicache_vecs};
LegacyFormat psit_fmt {psit_vecs};
#if SHAPELIB_ENABLED
- LegacyFormat shape_fmt {shape_vecs};
+ ShapeFormat shape_fmt;
#endif
LegacyFormat gpl_fmt {gpl_vecs};
LegacyFormat text_fmt {text_vecs};